package com.mysterymall.Controller;

import com.mysterymall.Common.Comp.Log;
import com.mysterymall.Model.Dto.PlaceAnOrderCallbackDto;
import com.mysterymall.Service.PaymentService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName com.mysterymall.Controller
 * @Description
 * @Author HuangWX
 * @Time 2023/12/18  17:05
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {


    private final PaymentService paymentService;

    /**
     * 构造器注入
     * @param paymentService 支付服务
     */
    public PaymentController(PaymentService paymentService) {
        this.paymentService = paymentService;
    }

    /**
     * 下单回调
     * @param mchNo 商户号
     * @param merchantOrderNo 商户订单号
     * @param ptOrderNo 平台订单号
     * @param amount 代付金额，支持2位小数
     * @param result 订单状态：1：支付成功
     * @param sign 签名值
     * @return String
     */
    @PostMapping("/placeAnOrderCallback")
    @Log
    public String placeAnOrderCallback(
            @RequestParam("mchNo") String mchNo,
            @RequestParam("merchantOrderNo") String merchantOrderNo,
            @RequestParam("ptOrderNo") String ptOrderNo,
            @RequestParam("amount") String amount,
            @RequestParam("result") String result,
            @RequestParam("sign") String sign) throws Exception {

        PlaceAnOrderCallbackDto placeAnOrderCallbackDto = new PlaceAnOrderCallbackDto();
        placeAnOrderCallbackDto.setMchNo(mchNo);
        placeAnOrderCallbackDto.setMerchantOrderNo(merchantOrderNo);
        placeAnOrderCallbackDto.setPtOrderNo(ptOrderNo);
        placeAnOrderCallbackDto.setAmount(amount);
        placeAnOrderCallbackDto.setResult(result);
        placeAnOrderCallbackDto.setSign(sign);
        return paymentService.placeAnOrderCallback(placeAnOrderCallbackDto);
    }
}
